$(document).ready(function () {
    $('#btnBuscar').on('click', function () {
        if( $("#formDigitalValidator").data("kendoValidator").validate() ){
            $.get(appBosch.urlChecker + '/' + $('#employees').val(), {}, function (res) {
                $('#result').html(res);
                $('.kbarcode').kendoBarcode({
                    value: $('.kbarcode').attr('codeforbar'),
                    type: "code128",
                    width: 250,
                    height: 60,
                    text: {
                        color: "black",
                        font: "11px Consolas, Monaco, Sans Mono, monospace, sans-serif !important",
                        margin: {
                            left: 15
                        }
                    }
                });
                $('.qrcode').kendoQRCode({
                    value: $('.qrcode').attr('code'),
                    size: 100,
                    color: $('.qrcode').attr('color'),
                    background: "transparent"
                });
                var date = $('#dateExp>p').data('date');
                $('#dateExp>p').append(' ' + kendo.toString(new Date(date.replace(/-/g, "/")), "D"));
            });
        }
    });
    
    if (appBosch.idToCheck !== '') {
        $('#btnBuscar').click();
    }

    $("#employees").kendoMaskedTextBox({
        mask: "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
    });
    
    var formKendo = $("#formDigitalValidator");
    kendo.init(formKendo);
    formKendo.kendoValidator({
        rules: {
            validmask: function (input) {
                
                if(input.is("[data-validmask-msg]") && input.val() != "") {
                    var maskedtextbox = input.data("kendoMaskedTextBox");
                    return maskedtextbox.value().indexOf(maskedtextbox.options.promptChar) === -1;
                }

                return true;
            }
        }
    });
    
    $("#employees").keyup(function(){
        $(".searchEmp .k-tooltip-validation").hide();
    });
});